package psico_test.gui;

import javax.swing.JOptionPane;

import psico_test.psicoTest;
import psico_test.appAdministrar.appAdministrar;

public class ventanaLogin extends javax.swing.JFrame
{
	
	private psicoTest controller;
	
	public ventanaLogin(psicoTest controller)
	{
		this.controller = controller;
		this.setUndecorated(true);
		initComponents();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}

	private void initComponents()
	{

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		textoUsuario = new javax.swing.JTextField();
		textoPass = new javax.swing.JPasswordField();
		botonLogin = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jLabel1.setText("Usuario");

		jLabel2.setText("Password");

		botonLogin.setText("Login");
		botonLogin.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				botonLoginActionPerformed(evt);
			}
		});

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout.createSequentialGroup()
						.addContainerGap()
						.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
								.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
										.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2)
										.add(org.jdesktop.layout.GroupLayout.LEADING, textoPass, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
										.add(org.jdesktop.layout.GroupLayout.LEADING, textoUsuario))
										.add(org.jdesktop.layout.GroupLayout.TRAILING, botonLogin, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
										.addContainerGap())
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(layout.createSequentialGroup()
						.addContainerGap()
						.add(jLabel1)
						.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
						.add(textoUsuario, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
						.add(jLabel2)
						.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
						.add(textoPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
						.add(botonLogin)
						.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);

		pack();
	}                        

	private void botonLoginActionPerformed(java.awt.event.ActionEvent evt)
	{                                           
		if((textoPass.getPassword().length==0)||(textoUsuario.getText().length()==0))
				JOptionPane.showMessageDialog(this,"Rellene todos los campos");
		else
			controller.login(textoUsuario.getText(),textoPass.getPassword());
	}                                          
	private javax.swing.JButton botonLogin;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JPasswordField textoPass;
	private javax.swing.JTextField textoUsuario;                 
}

